#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#define maxn 10010000
using namespace std;
int n,m;
int per[maxn];
int l[maxn];
int r[maxn];
int sign[maxn];
int ssign[maxn];
int a[maxn];
int belong[maxn];
int block;
int num;
void build()
{
	block = sqrt(n);
	num = n/block;
	if(n%block) num++;
	for(int i = 1;i<=num;i++)
	{
		l[i] = (i-1)*block+1;
		r[i] = i*block;
	}
	r[num] = n;
	for(int i = 1;i<=n;i++) belong[i] = (i-1)/block+1;
}
void ask(int x,int y)
{
	int ans = 0;
	if(belong[x]==belong[y])
	{
	//	printf("*****\n");
		for(int i = x;i<=y;i++)
		{
			if(per[i]<x) ans++;
		}
	}
	else 
	{
		//printf("****\n");
		for(int i = x;i<=r[belong[x]];i++)
		{
			//printf("***\n");
			if(per[i]<x) ans++;
		}
		for(int i = belong[x]+1;i<belong[y];i++)
		{
			//printf("****\n");
			int cnt = 0;
			for(int j = l[i];j<=r[i];j++)
			{
				ssign[cnt++] = per[j];
			}
			sort(ssign,ssign+cnt);
			int k = lower_bound(ssign,ssign+cnt,x)-ssign;
			ans +=k;
		}
		for(int i = l[belong[y]];i<=y;i++)
		{
			//printf("***%d\n",i);
			if(per[i]<x) ans++;
		}
	}
	printf("%d\n",ans);
}
void change(int x,int y)
{
	a[x] = y;
	memset(sign,0,sizeof(sign));
	for(int i = 1;i<=n;i++)
	{
		per[i] = sign[a[i]];
		sign[a[i]] = i;
	}
}
int main()
{
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		build();
		memset(sign,0,sizeof(sign));
		for(int i = 1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			per[i] = sign[a[i]];
			sign[a[i]] = i;
		}
		for(int i = 1;i<=m;i++)
		{
			int c,x,y;
			scanf("%c %d %d",&c,&x,&y);
			if(c=='Q') ask(x,y);
			else change(x,y);
		}
	}
}
